package com.eventapp.dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.eventapp.dao.EventDao;
import com.eventapp.model.Event;
import com.eventapp.model.EventPrivate;
import com.eventapp.model.EventPublic;


@Repository("eventDao")
public class EventDaoHibernate extends GenericDaoHibernate<Event, Long> implements EventDao {


    public EventDaoHibernate() {
        super(Event.class);
    }
    
    public List<EventPublic> getPublicEvents(){
    	
    	 Query qry = getSession().createQuery("from EventPublic e order by upper(e.date)");
         
    	 return qry.list();

    }
    
    public List<EventPublic> getPublicEventsByOwner(Long ownerId){
    	
   	 Query qry = getSession().createQuery("from EventPublic e where e.owner.id =:ownerId order by upper(e.date)");
     qry.setParameter("ownerId",ownerId);
   	 return qry.list();

   }
    
    
    
    
    
    public List<EventPrivate> getPrivateEventsByOwner(Long ownerId){
    	
   	 Query qry = getSession().createQuery("from EventPrivate e where e.owner.id =:ownerId order by upper(e.date");
     qry.setParameter("ownerId",ownerId);  
   	 return qry.list();

   }
    
    
 

    public Event saveEvent(Event event) {
        if (log.isDebugEnabled()) {
            log.debug("Event's id: " + event.getId());
        }

        getSession().saveOrUpdate(event);
        getSession().flush();
        return event;
    }

    



}
